package com.example.dllo.exe.giftspeak.jingxuan;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.dllo.exe.bean.JingXuanDangHangBean;
import com.example.dllo.exe.R;
import com.example.dllo.exe.fengzhuang.NetTool;
import com.squareup.picasso.Picasso;

/**
 * code is far away from bug with the animal protecting
 * <p>
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃永无BUG！  凯哥 祝你一路顺风
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 */
public class JingXuanRVAdapter extends RecyclerView.Adapter<JingXuanRVAdapter.MyVieHolder> {
    private Context context;
    JingXuanDangHangBean jingXuanDangHangBean;


    public JingXuanRVAdapter(Context context) {
        this.context = context;
    }

    public void setJingXuanDangHangBean(JingXuanDangHangBean jingXuanDangHangBean) {
        this.jingXuanDangHangBean = jingXuanDangHangBean;
        notifyDataSetChanged();
    }

    @Override
    public JingXuanRVAdapter.MyVieHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.jingxuanrvfragmentlayout, parent, false);
        MyVieHolder vieHolder = new MyVieHolder(view);
        return vieHolder;
    }

    @Override
    public void onBindViewHolder(JingXuanRVAdapter.MyVieHolder holder, int position) {

        NetTool netTool =new NetTool();
        netTool.getImage(jingXuanDangHangBean.getData().getSecondary_banners().get(position).getImage_url(),holder.ivrv_jinghua);
    }

    @Override
    public int getItemCount() {
        int c = jingXuanDangHangBean != null ? jingXuanDangHangBean.getData().getSecondary_banners().size() : 0;
        Log.d("JingXuanRVAdapter", "c:" + c);
        return jingXuanDangHangBean != null ? jingXuanDangHangBean.getData().getSecondary_banners().size() : 0;
    }

    public class MyVieHolder extends RecyclerView.ViewHolder {
        ImageView ivrv_jinghua;

        public MyVieHolder(View itemView) {
            super(itemView);
            ivrv_jinghua = (ImageView) itemView.findViewById(R.id.jingxuan_rv);
        }
    }
}
